package com.demo2do.boyle.common.entity.customer.wallet;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

import com.alibaba.fastjson.annotation.JSONField;
import com.demo2do.boyle.common.entity.customer.Customer;

/**
 * 
 * @author Wilson leo
 */
@Entity
@Table(name = "wallet")
public class Wallet {

	@Id
    @GeneratedValue(generator = "gen")
    @GenericGenerator(name = "gen", strategy = "foreign", parameters = @Parameter( name = "property", value = "customer"))
    private Integer id;

	/*@OneToOne(fetch = FetchType.LAZY)
	@PrimaryKeyJoinColumn
	@JSONField(serialize = false)
    private Customer customer;*/
	
	@ManyToOne(optional = false, fetch = FetchType.LAZY)
    @JSONField(serialize = false)
    private Customer customer;

    /** 账户余额 */
    private int balance;
    
    /** 冻结余额 */
    private int frozenAmount;

    /** 账户总收入 */
    private int totalIncome;

    /** 账户提现金额总计 */
    private int cashOut;

    private Date createTime;

    @Column(name = "is_deleted")
    private boolean disabled;

    /**
     * default constructor
     */
    public Wallet() {
    	
    }

    /**
     * the constructor using fields
     * 
     * @param customer
     */
    public Wallet(Customer customer) {
        this.balance = 0;
        this.totalIncome = 0;
        this.frozenAmount = 0;
        this.cashOut = 0;
        this.createTime = new Date();
        this.disabled = false;
        this.customer = customer;
    }
    
    /**
	 * add frozenAmount to wallet
	 * @param frozenAmount 
	 * @return
	 */
	public Wallet addFrozenAmount(int frozenAmount) {
		this.frozenAmount += frozenAmount * 100;
		return this;
	}
	
	/**
	 * 
	 * @param balance
	 * @return
	 */
	public Wallet withdrawal(int balance) {
		this.balance -= balance;
		this.frozenAmount -= balance;
		this.cashOut += balance;
		return this;
	}
	
	public Wallet audit(int balance) {
		this.balance += balance;
		this.totalIncome += balance;
		return this;
	}

	/**
	 * @return the id
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * @return the customer
	 */
	public Customer getCustomer() {
		return customer;
	}

	/**
	 * @return the balance
	 */
	public int getBalance() {
		return balance;
	}
	
	/**
	 * @return the frozenAmount
	 */
	public int getFrozenAmount() {
		return frozenAmount;
	}
	
	/**
	 * @return the totalIncome
	 */
	public int getTotalIncome() {
		return totalIncome;
	}

	/**
	 * @return the cashOut
	 */
	public int getCashOut() {
		return cashOut;
	}

	/**
	 * @return the createTime
	 */
	public Date getCreateTime() {
		return createTime;
	}

	/**
	 * @return the disabled
	 */
	public boolean isDisabled() {
		return disabled;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * @param customer the customer to set
	 */
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	/**
	 * @param balance the balance to set
	 */
	public void setBalance(int balance) {
		this.balance = balance;
	}
	
	/**
	 * @param frozenAmount the frozenAmount to set
	 */
	public void setFrozenAmount(int frozenAmount) {
		this.frozenAmount = frozenAmount;
	}

	/**
	 * @param totalIncome the totalIncome to set
	 */
	public void setTotalIncome(int totalIncome) {
		this.totalIncome = totalIncome;
	}

	/**
	 * @param cashOut the cashOut to set
	 */
	public void setCashOut(int cashOut) {
		this.cashOut = cashOut;
	}

	/**
	 * @param createTime the createTime to set
	 */
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	/**
	 * @param disabled the disabled to set
	 */
	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}
    
}
